
#include<string.h>
#include<unistd.h>
#include"process.h"

#define NUM 101
#define SSTYLE '='

void FFlushProcess(double current, double total)
{
  char buffer[NUM];
  memset(buffer, 0, sizeof(buffer));

  const char* lable = "|\\-/";
  int len = strlen(lable);
  double rate = current / total;
  int cnt = rate * 100;
  
  int i = 0;
  for(;i < cnt; i++)
  {
    buffer[i] = SSTYLE;
  }
  printf("[%-100s][%lf%%][%c]\r", buffer, rate*100, lable[cnt%len]);
  fflush(stdout);
}

void prcess_v1()
{
  char buffer[NUM];
  memset(buffer, 0, sizeof(buffer));
  char* lable = "|/-\\";
  int len = strlen(lable);
  int cnt = 0;
  while(cnt <= 100)
  {
    printf("[%-100s][%d%%][%c]\r", buffer, cnt, lable[cnt%len]);
    fflush(stdout);
    buffer[cnt] = SSTYLE;
    cnt++;
    usleep(3000);
  }
  printf("\n");
}
